﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using TyMES.Model.BaseInformation;
using TyMES.Model;

namespace TyMES.ViewModel.BaseInformation.FactoryVMs
{
    public partial class FactoryListVM : BasePagedListVM<Factory_View, FactorySearcher>
    {
        
        protected override IEnumerable<IGridColumn<Factory_View>> InitGridHeader()
        {
            return new List<GridColumn<Factory_View>>{
                
                this.MakeGridHeader(x => x.Factory_FactoryCode).SetTitle(@Localizer["Page.工厂编码"].Value),
                this.MakeGridHeader(x => x.Factory_FactoryName).SetTitle(@Localizer["Page.工厂名称"].Value),
                this.MakeGridHeader(x => x.Factory_ManagerID).SetTitle(@Localizer["Page.负责人工号"].Value),
                this.MakeGridHeader(x => x.Factory_ManagerName).SetTitle(@Localizer["Page.负责人姓名"].Value),
                this.MakeGridHeader(x => x.Factory_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.Factory_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.Factory_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.Factory_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),
                this.MakeGridHeader(x => x.Factory_IsValid).SetTitle(@Localizer["_Admin.IsValid"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<Factory_View> GetSearchQuery()
        {
            var query = DC.Set<Factory>()
                
                .CheckContain(Searcher.FactoryCode, x=>x.FactoryCode)
                .CheckContain(Searcher.FactoryName, x=>x.FactoryName)
                .CheckContain(Searcher.ManagerID, x=>x.ManagerID)
                .CheckContain(Searcher.ManagerName, x=>x.ManagerName)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new Factory_View
                {
				    ID = x.ID,
                    
                    Factory_FactoryCode = x.FactoryCode,
                    Factory_FactoryName = x.FactoryName,
                    Factory_ManagerID = x.ManagerID,
                    Factory_ManagerName = x.ManagerName,
                    Factory_CreateTime = x.CreateTime,
                    Factory_UpdateTime = x.UpdateTime,
                    Factory_CreateBy = x.CreateBy,
                    Factory_UpdateBy = x.UpdateBy,
                    Factory_IsValid = x.IsValid,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class Factory_View: Factory
    {
        
        public string Factory_FactoryCode { get; set; }
        public string Factory_FactoryName { get; set; }
        public string Factory_ManagerID { get; set; }
        public string Factory_ManagerName { get; set; }
        public DateTime? Factory_CreateTime { get; set; }
        public DateTime? Factory_UpdateTime { get; set; }
        public string Factory_CreateBy { get; set; }
        public string Factory_UpdateBy { get; set; }
        public bool Factory_IsValid { get; set; }

    }

}